<?php

class RecommedBookController extends Controller
{
	public function actionIndex()
	{
		if(isset($_GET['idgenre'])){
				$idgenre = $_GET['idgenre'];
				$criteria1 = new CDbCriteria;
				$criteria1->alias = 'book';
				$criteria1->limit = 8;
				$criteria1->join = "INNER JOIN book_genre on book_genre.idbook = book.idbook INNER JOIN genre on genre.idgenre = book_genre.idgenre";
				$criteria1->addCondition("genre.idgenre = $idgenre");
				$criteria1->order = "point DESC, rateclick desc, download desc";
				$recommendBook = new CActiveDataProvider(Book::model(),
						array(
						'criteria' => $criteria1,
						'pagination' => array('pageSize'=>8, )
						)
					);
			$this->render('index',array('recommendBook'=>$recommendBook));
		 }else{
			 $criteria1 = new CDbCriteria;
				$criteria1->alias = 'book';
				$criteria1->limit = 8;
				$criteria1->order = "point DESC";
				$recommendBook = new CActiveDataProvider(Book::model(),
						array(
						'criteria' => $criteria1,
						'pagination' => array('pageSize'=>8, )
						)
					);
			$this->render('index',array('recommendBook'=>$recommendBook));
		}
	}
	static function  getProviderRecommendBook($idgenre)
	{
		$criteria1 = new CDbCriteria;
		$criteria1->alias = 'book';
		$criteria1->limit = 8;
		$criteria1->join = "INNER JOIN book_genre on book_genre.idbook = book.idbook INNER JOIN genre on genre.idgenre = book_genre.idgenre";
		$criteria1->addCondition("genre.idgenre = $idgenre");
		$criteria1->order = "point DESC";
		$recommendBook = new CActiveDataProvider(Book::model(),
				array(
				'criteria' => $criteria1,
				'pagination' => array('pageSize'=>8, )
				)
			);
		return $recommendBook;
	}
	// Uncomment the following methods and override them if needed
	/*
	public function filters()
	{
		// return the filter configuration for this controller, e.g.:
		return array(
			'inlineFilterName',
			array(
				'class'=>'path.to.FilterClass',
				'propertyName'=>'propertyValue',
			),
		);
	}

	public function actions()
	{
		// return external action classes, e.g.:
		return array(
			'action1'=>'path.to.ActionClass',
			'action2'=>array(
				'class'=>'path.to.AnotherActionClass',
				'propertyName'=>'propertyValue',
			),
		);
	}
	*/
}